<%--
  Created by IntelliJ IDEA.
  User: lixiaodong
  Date: 2018/4/3
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="user_index_div" class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center'" style="">
        <table id="user_index_dg_user" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'east'" style="width: 600px;">
        <table id="user_index_dg_role" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="user_index_toolbar_user">
    <a id="user_index_add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">添加用户</a>|
    <a id="user_index_update" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改用户</a>|
    <a id="user_index_delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">删除用户</a>
</div>
<div id="user_index_toolbar_role">
    <a id="user_index_delete_role" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">删除用户的角色</a>
</div>

<script type="text/javascript">
    var _user_index_js = {
        role_init : function (_queryParams) {
            var _columns = [[
                {field:'id',title:'ID',width:0,hidden:'true'},
                {field:'name',title:'角色名称',width:100},
                {field:'number',title:'角色编号',width:100},
                {field:'introduce',title:'角色说明',width:300},
                {field:'state',title:'状态',width:100},
            ]];
            var _url = bs.base_url + 'user/getRoles.action';
            bs.datagrid_load('user_index_dg_role',_columns,_url,'user_index_toolbar_role',_queryParams);
            //$('#user_index_dg_role').datagrid({pagination:false});
        },
        datagrid_init : function (_queryParams) {
            var _columns = [[
                {field:'id',title:'ID',width:0,hidden:'true'},
                {field:'person',title:'person',width:0,hidden:'true'},
                {field:'userName',title:'用户名',width:100},
                {field:'person_name',title:'姓名',width:100,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.name==null?"":row.person.name);
                        }
                        return "未指定";
                    }},
                {field:'person_phone',title:'电话',width:100,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.phone==null?"":row.person.phone);
                        }
                        return "未指定";
                    }},
                {field:'person_qq',title:'QQ',width:100,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.qq==null?"":row.person.qq);
                        }
                        return "未指定";
                    }},
                {field:'person_email',title:'邮箱',width:100,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.email==null?"":row.person.email);
                        }
                        return "未指定";
                    }},
                {field:'state',title:'状态',width:100},

            ]];
            var _url = bs.base_url + 'user/getByPage.action';
            bs.datagrid_load('user_index_dg_user',_columns,_url,'user_index_toolbar_user',_queryParams);
            $('#user_index_dg_user').datagrid({
                onClickRow:function (index, row) {
                    _user_index_js.role_init({id:row.id})
                }
            });
        },
        btn_init : function () {
            $('#user_index_add').on('click', function () {
                bs.show_dialog_min('user_dialog',bs.base_url+'user/addUI.action','添加用户',{flag:'add'});
            });
            $('#user_index_update').on('click', function () {
                var _row = $('#user_index_dg_user').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url+'user/addUI.action';
                    var _queryParams = {row:_row, flag:'update'};
                    bs.show_dialog_min('user_dialog',_url,'修改用户信息',_queryParams);
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#user_index_delete').on('click', function () {
                var _row = $('#user_index_dg_user').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url + 'user/delete.action?id='+_row.id;
                    bs.base_ajax_datagrid(_url,'user_index_dg_user','您确认想要删除这个角色信息吗？');
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#user_index_delete_role').on('click', function () {
                var _row0 = $('#user_index_dg_user').datagrid('getSelected');
                var _row1 = $('#user_index_dg_role').datagrid('getSelected');
                if (_row0 != null && _row1 != null){
                    var _url = bs.base_url + 'user/deleteRole.action?id='+_row0.id + '&roleId=' + _row1.id;
                    bs.base_ajax_datagrid(_url,'user_index_dg_role','您确认想要解除这个角色吗？');
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
        }
    }

    var user_index_app = (function () {
        $(function () {
            _user_index_js.datagrid_init(null);
            _user_index_js.btn_init();
        });
    })();
</script>